package pl.edu.agh.nn.data.producer;

import java.util.ArrayList;
import java.util.List;

import pl.edu.agh.nn.conf.InvalidNetworkConfigurationException;
import pl.edu.agh.nn.data.NetData;

public class StdoutOutputProducer implements OutputDataProducer {

	private List<NetData> outputData;

	public StdoutOutputProducer() {

	}

	@Override
	public void produce(double[] result) {
		outputData.add(new NetData(result));
	}

	@Override
	public void configure() throws InvalidNetworkConfigurationException {
		this.outputData = new ArrayList<NetData>();
	}

	@Override
	public void finish() {
		saveDataToFile();
	}

	private void saveDataToFile() {
		StringBuilder builder = new StringBuilder();
		for (NetData data : outputData) {
			for (double d : data.getData()) {
				builder.append(d).append(", ");
			}
			builder.append("\n");
		}
		System.out.println(builder.toString());
	}

}
